#include <mainwindow.h>
#include <QIcon>
#include <QToolBar>
#include <stdio.h>
#include <QMenu>
#include <QMenuBar>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
  InitActions ();
  InitGUI();
}


void MainWindow::InitActions()
{
  _actions[Action_Save]           = new QAction (QIcon (":/icons/media/save.png"), "Save", this);
  _actions[Action_SaveAll]        = new QAction (QIcon (":/icons/media/save_all.png"), "Save all", this);
  _actions[Action_Compile]        = new QAction (QIcon (":/icons/media/compile.png"), "Compile", this);

  _actions[Action_MaterialView]   = new QAction ("Mat", this);
  _actions[Action_ObjectBrowser]  = new QAction ("Obj", this);
  _actions[Action_ObjectComposer]  = new QAction ("Cmp", this);

  _actions[Action_Save]->setShortcut(QKeySequence("Ctrl+s"));
  _actions[Action_Compile]->setShortcut(QKeySequence("F11"));
  _actions[Action_MaterialView]->setShortcut(QKeySequence("F1"));
  _actions[Action_ObjectBrowser]->setShortcut(QKeySequence("F2"));
  _actions[Action_ObjectComposer]->setShortcut(QKeySequence("F3"));

  _actions[Action_MaterialView]->setCheckable(true);
  _actions[Action_ObjectBrowser]->setCheckable(true);
  _actions[Action_ObjectComposer]->setCheckable(true);
}

void MainWindow::InitGUI()
{
  QToolBar* tb = new QToolBar ();
  tb->addAction(_actions[Action_Save]);
  tb->addAction(_actions[Action_SaveAll]);
  tb->addAction(_actions[Action_Compile]);
  tb->addSeparator();
  tb->addAction(_actions[Action_MaterialView]);
  tb->addAction(_actions[Action_ObjectBrowser]);
  tb->addAction(_actions[Action_ObjectComposer]);

  addToolBar(tb);

  QMenuBar* menu = menuBar();

  QAction* fileExit = new QAction ("E&xit", this);

  QMenu* menuFile = menu->addMenu("&File");
  menuFile->addAction(fileExit);

  menu->addMenu(menuFile);

}

QAction* MainWindow::GetAction(Action action)
{
  return _actions[action];
}
